using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DTO;
namespace DAO  
{
    public class ChuyenBayDAO
    {
        public static bool ChonHetChuyenBay(List<DTO.ChuyenBay> danhsach)
        {
            string sql = "Select * from ChuyenBay ";
            DataTable dt= Config.AccessHelper.ExecuteQuery(sql);
            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DTO.ChuyenBay cb = new DTO.ChuyenBay();
                    cb.MaChuyenBay = dt.Rows[i].ItemArray[0].ToString();
                    cb.NgayBay=DateTime.Parse(dt.Rows[i].ItemArray[1].ToString());
                    cb.ThoiGian = DateTime.Parse(dt.Rows[i].ItemArray[2].ToString());
                    cb.SoGheThuongGia = int.Parse(dt.Rows[i].ItemArray[3].ToString());
                    cb.SoGhePhoThong = int.Parse(dt.Rows[i].ItemArray[4].ToString());
                    cb.MaSanBayDi = int.Parse(dt.Rows[i].ItemArray[5].ToString());
                    cb.MaSanBayDen = int.Parse(dt.Rows[i].ItemArray[6].ToString());
                    cb.MaLoaiMayBay = int.Parse(dt.Rows[i].ItemArray[7].ToString());
                    danhsach.Add(cb);
                    
                }
                return true;
            }
            return false;
        }
        public static bool CapNhatChuyenBay(DTO.ChuyenBay temp)
        {
            try
            {
                string sql = "UPDATE ChuyenBay SET SoGheHangThuongGia=" + temp.SoGheThuongGia.ToString() + ",NgayBay = '" + temp.NgayBay.ToShortDateString() + "', ThoiGianBay = '" + temp.ThoiGian.ToShortTimeString() + "', SoGheHangPhoThong =" + temp.SoGhePhoThong.ToString() + ", MaSanBayDi =" + temp.MaSanBayDi.ToString() + ", MaSanBayDen =" + temp.MaSanBayDen.ToString() + ", MaLoaiMayBay =" + temp.MaLoaiMayBay + " WHERE MaChuyenBay = '" + temp.MaChuyenBay.ToString() + "'";
                //MaChuyenBay = '" + temp.MaChuyenBay.ToString() + "', NgayBay = '" + temp.NgayBay.ToShortDateString() + "', ThoiGianBay = '" + temp.ThoiGian.Hour.ToString() +":"+temp.ThoiGian.Minute.ToString() + "', SoGheThuongHang =" +temp.SoGheThuongGia.ToString()+", SoGhePhoThong =" + temp.SoGhePhoThong.ToString() + ", MaSanBayDi =" + temp.MaSanBayDi.ToString() +", MaSanBayDen =" + temp.MaSanBayDen.ToString() +", MaLoaiMayBay =" +temp.MaLoaiMayBay ;
                Config.AccessHelper.ExecuteNonQuery(sql);
                
                return true;
            }
            catch 
            {
            	return false;
            }
            
            
        }
        public static bool ThemChuyenBay(DTO.ChuyenBay cb)
        {
            try
            {
                string sql = "insert into ChuyenBay(MaChuyenBay,NgayBay,ThoiGianBay,MaSanBayDi,MaSanBayDen,SoGheHangThuongGia,SoGheHangPhoThong,MaLoaiMayBay) values ('";
                sql += cb.MaChuyenBay + "','";
                sql += cb.NgayBay + "','";
                sql += cb.ThoiGian + "','";
                sql += cb.MaSanBayDi + "','";
                sql += cb.MaSanBayDen + "','";
                sql += cb.SoGheThuongGia + "','";
                sql += cb.SoGhePhoThong + "','";
                sql += cb.MaLoaiMayBay + "')";
                Config.AccessHelper.ExecuteQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }

         }

        //public static bool Chondoanhthu(DTO.DoanhThuThang dt)
            

    }

   
}
